home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
comm
/
term
/
vltj5867.lha
/
VLT
/
rexx
/
X10Direct.vlt
< prev
Wrap
Text File
|
1994-03-27
|
6KB
|
237 lines
/** X10Direct.vlt
*
* This program brings up a requester which allows you to send commands
* to X10 modules.
*
* By W.G.J. Langeveld, July 1992.
*
* This program really wants to be called *from inside* VLT.
*
* Below is a sample house code, and examples for the various units
* for that housecode. Defaults are set up for all other house codes.
*
**/
do i = 1 to 16
do j = 0 to 15
hc = substr("ABCDEFGHIJKLMNOP", i, 1)
gtext.hc.j = "Unit "left(j, 2)" "
end
end
housecode = "L"
gtext.L.0 = "Unit 1 Living room light "
gtext.L.1 = "Unit 2 Kitchen light "
gtext.L.2 = "Unit 3 Dining Room light "
gtext.L.3 = "Unit 4 Bedroom Light "
/*
* Add the libraries if they're not there yet.
*/
if show("l", "rexxarplib.library") = 0 then do
check = addlib('rexxsupport.library', 0, -30, 0)
check = addlib('rexxarplib.library', 0, -30, 0)
end
/*
* The following sequence determines both VLT's screen and port name,
* and also gets the number screen rows and columns.
*/
vltport = address()
cols = ScreenCols(vltport)
if cols == -1 then do
vltscreen = ""
cols = ScreenCols()
rows = ScreenRows()
end
else do
vltscreen = vltport
rows = ScreenRows(vltscreen)
end
/*
* Set up a host. This time, send all messages to our own port.
*/
address AREXX "'x = CreateHost(VLTX10DIRECT, VLTX10PORT, "vltscreen")'"
/*
* Wait until it is ready.
*/
do i = 1
if showlist('p', VLTX10DIRECT) ~= 0 then leave
call delay 30
end
/*
* Open the window
*/
idcmp = 'CLOSEWINDOW+GADGETUP'
flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
call SetReqColor(VLTX10DIRECT, BACKGROUNDPEN, 0)
call OpenWindow(VLTX10DIRECT, (cols - 640)/2, rows - 170, 640, 170, idcmp, ,
flags, "X10 Control Panel")
/*
* Open the port that messages will come to
*/
mp = openport(VLTX10PORT)
/*
* Add the gadgets
*/
call MakeGadgets(housecode)
/*
* Set VLT for 600 bps
*/
"extract baud"
lastbaud = VLT.baud
"baud midi 600"
/*
* Main loop
*/
x10state. = 0
quitflag = 0
do forever
if quitflag = 1 then leave
t = waitpkt(VLTX10PORT)
do forever
p = getpkt(VLTX10PORT)
if c2d(p) = 0 then leave
cmd = getarg(p)
t = reply(p, 0)
/*
* See what we got
*/
parse var cmd cmd mousex .
if cmd = "CLOSEWINDOW" then do
/*
* Reset VLT's baud rates.
*/
"baud "lastbaud
call CloseWindow(VLTX10DIRECT)
quitflag = 1
end
else if cmd = "HC" then do
res = Request(100, screenrows(vltscreen) - 150, "Enter new house code", ,
housecode, , "Cancel", vltscreen)
if res ~= "" then do
res = upper(substr(res, 1, 1))
if index("ABCDEFGHIJKLMNOP", res) = 0 then do
call PostMsg(100, screenrows(vltscreen) - 150, ,
"Invalid hose code: "res, vltscreen)
call Delay(100)
call PostMsg()
end
else if res ~= housecode then do
housecode = res
do i = 0 to 15
call RemoveGadget(VLTX10DIRECT, i)
end
call MakeGadgets(housecode)
end
end
end
else if datatype(cmd, 'W') = 1 then do
if cmd < 8 then mousex = mousex - 10
else mousex = mousex - 324
if mousex > 150 then call SendCommand(housecode, cmd, "on")
else call SendCommand(housecode, cmd, "off")
end
end
end
exit
MakeGadgets: procedure expose gtext.
parse arg hc
call SetAPen(VLTX10DIRECT, 0)
call RectFill(VLTX10DIRECT, 5, 15, 633, 166)
prompts = ,
"Off On || Off On"
call WindowText(VLTX10DIRECT, prompts)
call AddGadget(VLTX10DIRECT, 10, 32, 0, gtext.hc.0 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 46, 1, gtext.hc.1 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 60, 2, gtext.hc.2 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 74, 3, gtext.hc.3 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 88, 4, gtext.hc.4 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 102, 5, gtext.hc.5 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 116, 6, gtext.hc.6 , "%d %x")
call AddGadget(VLTX10DIRECT, 10, 130, 7, gtext.hc.7 , "%d %x")
call AddGadget(VLTX10DIRECT, 324, 32, 8, gtext.hc.8 , "%d %x")
call AddGadget(VLTX10DIRECT, 324, 46, 9, gtext.hc.9 , "%d %x")
call AddGadget(VLTX10DIRECT, 324, 60, 10, gtext.hc.10, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 74, 11, gtext.hc.11, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 88, 12, gtext.hc.12, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 102, 13, gtext.hc.13, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 116, 14, gtext.hc.14, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 130, 15, gtext.hc.15, "%d %x")
call AddGadget(VLTX10DIRECT, 324, 150, 20, "Change House Code", "HC")
call Move(VLTX10DIRECT, 10, 157)
call SetAPen(VLTX10DIRECT, 1)
call Text(VLTX10DIRECT, "Current house code: "hc)
return
SendCommand: procedure
arg housecode, unit, cmd
/*
* Clear screen
*/
"clear"
/*
* Some data strings we'll use.
*/
syncstring = copies("*xFF", 16)
houseseq = "MECKOGAINFDLPHBJ"
/*
* Start calculating the checksum by using the housecode byte.
*/
cs = (index(houseseq, housecode) - 1) * 16
hc = "*x" || d2x(cs, 2)
command.17 = "*x01"
if upper(cmd) = "OFF" then do
command.18 = "*x03"
cs = cs + 3
call SetGadget("VLTX10DIRECT", unit, "OFF")
end
else if upper(cmd) = "ON" then do
command.18 = "*x02"
cs = cs + 2
call SetGadget("VLTX10DIRECT", unit, "ON")
end
command.19 = hc
if unit < 8 then do
command.20 = "*x00"
active = 21
end
else do
command.21 = "*x00"
active = 20
unit = unit - 8
end
command.active = "*x" || d2x(2 ** (7 - unit), 2)
cs = cs + 2 ** (7 - unit)
cs = cs // 256
command.22 = "*x" || d2x(cs, 2)
"send (" || syncstring || command.17 || command.18 || command.19 || ,
command.20 || command.21 || command.22 || ")"
"wait ("hc") 3"
return